package cn.com.gainfo.bktas.business;

import java.util.List;

import javax.sql.DataSource;

import cn.com.gainfo.bktas.dao.DepartmentDAO;
import cn.com.gainfo.bktas.vo.DepartmentVO;
import cn.yzyue.base.business.AbstractBusiness;
import cn.yzyue.base.vo.VO;

public class DepartmentBusiness extends AbstractBusiness{

	private DepartmentDAO dao = null;
	
	public DepartmentBusiness(){
		dao = new DepartmentDAO();
	}
	
	@Override
	public boolean add(DataSource dataSource, VO vo) {
		
		return dao.add(dataSource, vo);
	}
	
	@Override
	public boolean del(DataSource dataSource, VO vo, String[] ids) {
		
		return dao.del(dataSource, vo, ids);
	}
	
	@Override
	public List find(DataSource dataSource, String sql) {
		
		return dao.find(dataSource, sql);
	}
	
	@Override
	public boolean mod(DataSource dataSource, VO vo) {
		DepartmentVO dvo = (DepartmentVO) vo;
		String sql = "update department set deptName='"+dvo.getDeptName()+"' where deptId ="+dvo.getDeptId();
		return dao.mod(dataSource, vo);
	}
	
	public String getFindSql(){
		String sql = "select * from department";
		return sql;
	}
	
	public boolean checkExists(DataSource dataSource,String deptname){
		int count = dao.checkExists(dataSource,deptname);
		return count==0?false:true;
	}
	
	public VO getVo(DataSource dataSource, String id) {
		List list = dao.getVo(dataSource,id);
		DepartmentVO dvo = new DepartmentVO();
		if(list != null && list.size() > 0){
			String[] temp = (String[]) list.get(0);
			dvo.setDeptId(Integer.parseInt(temp[0]));
			dvo.setDeptName(temp[1]);
		}
		return dvo;
	}
	
}
